package com.eascs.web.p2p.action;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.dubbo.config.annotation.Reference;
import com.eascs.app.dao.PageResult;
import com.eascs.common.util.UrlUtil;
import com.eascs.p2p.common.vo.InvestorWithdrawRecordVO;
import com.eascs.p2p.common.vo.ModelResult;
import com.eascs.p2p.common.wallet.service.InvestorWalletService;
import com.eascs.site.page.PaginationInfo;
import com.eascs.site.view.BaseRestResult;
import com.eascs.site.view.ViewContext;
import com.eascs.site.view.button.AjaxButton;
import com.eascs.site.view.button.Button;
import com.eascs.site.view.button.ShowButtonFilter;
import com.eascs.tag.MenuTag;
import com.eascs.web.p2p.common.BaseMasterViewController;

@Controller
@RequestMapping("/withdraw")
public class WithdrawController extends BaseMasterViewController {

	@Reference
	InvestorWalletService  investorWalletService;
	@Value("${web.font.url}")
	private String fontUrl;
	@Override
	public void preHandle() {
		super.preHandle();
		ViewContext.put(MenuTag.CURRENT_MENU_CODE, "WithdrawManerger");
	}

	
	@RequestMapping(value = "/index")
	public String index(InvestorWithdrawRecordVO vo) {

		vo.setPageSize(10);
		ModelResult<PageResult<Object[]>> model = investorWalletService.findPageInvestorWithdrawRecord(vo);
		PageResult<Object[]> pageResult = new PageResult<Object[]>();
		if (model.isSuccess()) {
			pageResult = model.getModel();
		}

		String[] titles = { "提现申请流水号", "提现人", "提现金额","提现时间", "状态" };
		AjaxButton Button1=new AjaxButton("  审核", "/withdrawRest/to_check?id=");
		Button1.setShowButtonFilter(new ShowButtonFilter() {
			
			@Override
			public boolean filter(Object param) {
				Object[] params=(Object[]) param;
				return "未审核".equals(params[5]);
			}
		});
		
		
		AjaxButton Button2=new AjaxButton("  放款", fontUrl+"member/rest/withdrawByAdmin?id=");
		Button2.setShowButtonFilter(new ShowButtonFilter() {
			
			@Override
			public boolean filter(Object param) {
				Object[] params=(Object[]) param;
				return "审核通过".equals(params[5]);
			}
		});

		Button[] detailButton = new Button[] {Button1,Button2};
		String pageUrl = "/withdraw/index";
		pageUrl = UrlUtil.appendUrl(pageUrl, "name", vo.getName());
		pageUrl = UrlUtil.appendUrl(pageUrl, "requestno", vo.getRequestno());
		pageUrl = UrlUtil.appendUrl(pageUrl, "beginCreateTime", vo.getBeginCreateTime());
		pageUrl = UrlUtil.appendUrl(pageUrl, "endCreateTime", vo.getEndCreateTime());
		pageUrl = UrlUtil.appendUrl(pageUrl, "status", vo.getStatus());
		pageUrl = UrlUtil.appendUrl(pageUrl, "showPage", "");
		PaginationInfo paginationInfo = new PaginationInfo(pageResult, titles, pageUrl);
		paginationInfo.setBuildPagingNavigation(true);
		// paginationInfo.setFirstRenderColumnIndex(1);
		paginationInfo.setMoreButtons(detailButton);
		ViewContext.put("paginationInfo", paginationInfo);
		ViewContext.put("vo", vo);

		BaseRestResult.refresh();
		return "/withdraw/index";
	}

	
}
